package cn.icare.cms.impl;

import cn.icare.cms.ConfigService;
import cn.icare.cms.dao.mapper.ConfigMapper;
import cn.icare.cms.dao.po.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ConfigServiceImpl implements ConfigService {

    @Resource
    private ConfigMapper configMapper;


    private final Logger logger = LoggerFactory.getLogger(CouponServiceImpl.class);

    private final String itemDetailKey = "itemdetail_footer";


    @Override
    public Config getOne(String key) {
        return configMapper.selectByPrimaryKey(key);
    }

    @Override
    public boolean save(Config config) {
        String key = config.getKeyname();
        int result = 0;
        if (this.getOne(key) != null) {
            result = this.configMapper.updateByPrimaryKeySelective(config);
        } else {
            result = this.configMapper.insertSelective(config);
        }
        return result > 0;
    }

    @Override
    public Config getItemDetailFooter() {

        return getOne(itemDetailKey);
    }

    @Override
    public boolean saveItemDetailFooter(String value) {
        Config config = new Config();
        config.setKeyname(itemDetailKey);
        config.setKeyvalue(value);
        return save(config);
    }
}
